home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MISC / SHELL.ARC / Shell / Sources / c / GenArray < prev    next >
Text File  |  1994-06-25  |  2KB  |  119 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "DeskLib:WimpSWIs.h"
  5.  
  6. #include "Shell.Array.h"
  7. #include "Shell.Extra.h"
  8. #include "Shell.SafeAlloc.h"
  9.  
  10.  
  11.  
  12.  
  13. typedef struct    {
  14.     Shell_GeneralArrayFn    fn;
  15.     Shell_GeneralArrayInfo    info;
  16.     }
  17.     Shell_GeneralArrayInfoInternal;
  18.  
  19.  
  20.  
  21.  
  22.  
  23. static void    Shell_GeneralArrayRedrawer(
  24.     Shell_convertpoint    convert,
  25.     wimp_point        rectsize,
  26.     void            *reference,
  27.     const wimp_rect        *redrawrect
  28.     )
  29. {
  30.     wimp_rect            rect    = *redrawrect;
  31.     Shell_GeneralArrayInfoInternal    *info    = (Shell_GeneralArrayInfoInternal *) reference;
  32.  
  33. Shell_ConvertToSubTextRect2( &rect, rectsize);
  34.  
  35. rect.min.x /= info->info.width;
  36. rect.max.x /= info->info.width;
  37.  
  38.  
  39.     {    int i, j;
  40.     for ( i=rect.min.x; i<=rect.max.x; i++)    {
  41.         int x = i*Shell_TEXTXSIZE*info->info.width;
  42.         for ( j=rect.min.y; j<=rect.max.y; j++)    {
  43.             Shell_PrintString( info->fn( i, j, &info->info),
  44.                 x, rectsize.y - j*Shell_TEXTYSIZE,
  45.                 convert);
  46.             }
  47.         }
  48.     }
  49. return;
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. static BOOL Shell_GeneralArraySaver( char *filename, Shell_rectblock *r)
  57. {
  58. FILE                *f;
  59. Shell_GeneralArrayInfoInternal    *info    = (Shell_GeneralArrayInfoInternal *) r->reference;
  60. int                x, y;
  61.  
  62. f = fopen( filename, "w");
  63. if (!f) return FALSE;
  64.  
  65. for ( y=0; y<info->info.size.y; y++)    {
  66.     for ( x=0; x<info->info.size.x; x++)    {
  67.         fprintf( f, info->fn( x, y, &info->info));
  68.         fprintf( f, "\t");
  69.         }
  70.     fprintf( f, "\n");
  71.     }
  72. fclose(f);
  73. return TRUE;
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. Shell_rectblock    *Shell_AddGeneralArray(
  81.     Shell_windblock *windblock,
  82.     int x, int y,
  83.     int xsize, int ysize,
  84.     int width,
  85.     const char *format,
  86.     Shell_GeneralArrayFn fn,
  87.     const void *data,
  88.     int forecol, int backcol
  89.     )
  90.  
  91. {    wimp_rect            rect;
  92.     Shell_rectblock            *r;
  93.     Shell_GeneralArrayInfoInternal    *info =
  94.         Shell_SafeMalloc( sizeof( Shell_GeneralArrayInfoInternal));
  95.  
  96. info->fn        = fn;
  97. info->info.width    = width;
  98. info->info.data        = (void *) data;
  99. info->info.forecol    = forecol;
  100. info->info.backcol    = backcol;
  101. info->info.size.x    = xsize;
  102. info->info.size.y    = ysize;
  103.  
  104. strcpy( info->info.format, format);
  105.  
  106. rect.max.x = x+xsize*width*Shell_TEXTXSIZE;
  107. rect.max.y = y;
  108. rect.min.x = x;
  109. rect.min.y = y-ysize*Shell_TEXTYSIZE;
  110.  
  111. r = Shell_AddRectangle( windblock, &rect, Shell_GeneralArrayRedrawer, (void *) info);
  112. r->saver = Shell_GeneralArraySaver;
  113. Shell_MakeRectIcon( r, forecol, backcol, "R2");
  114.  
  115. return r;
  116. }
  117.  
  118.  
  119.